import java.io.IOException;
import java.net.Socket;

/**
*  class Client:
*    - initialise player 
*    - create read thread (and write thread start in the read thread)
*    - set connection to server
*/ 
public class Client {
	private boolean backup;
	
	public Client(String serverIp, String localIP, String localName) {
		Socket socket = null;
		backup = false;
		
		Player player = new Player(localName);
		
		try {
			socket = new Socket(serverIp, 4701); 
			new TimeThread().start();
			System.out.println("connect to server!");
			
			// new IO thread
			new ClientReadThread(socket, player).start();
			
			
		} catch (IOException e) {
			e.printStackTrace();
			try {
				socket.close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
	}

	public boolean isBackup() {
		return backup;
	}

	public void setBackup(boolean backup) {
		this.backup = backup;
	}
}
